#' Get the packages information
#' 
#' @description `output_require` can output the packages information you have installed, It help you to 
#' reconstruct the environment.
#' @param libs the library path you installed the packages
#' @param outputpath the path where store the files output
#' @author Jeason Zhao 
#' @example 
#' \dontrun{
#'   output_require()
#' }

output_require <- function(libs = NULL, outputpath = NULL) {
  ## read all installed packages information
  info <- as.data.frame(installed.packages())
  ## get the information of choosed library
  message("Getting installed packages information ...")
  if (is.null(libs)) {
    message(paste("Library path:", paste(.libPaths(), collapse = " ")))
    out_pkgs <- info[, c("Package", "Version")]
  } else {
    message(paste("Library path:", libs))
    out_pkgs <- info[info$LibPath != libs, c("Package", "Version")]
  }
  ## write the information into .txt file
  if (is.null(outputpath)) {
    out_path <- paste0(getwd(), "/requirement.txt")
  } else {
    out_path <- paste0(outputpath, "/requirement.txt")
  }
  message(paste("Writing the requirement into", out_path))
  write.table(out_pkgs, file = out_path, quote = F, row.names = F)
}